//go:generate go run github.com/vektah/dataloaden UserLoader int64 *gql/graph/model.User

package model

import (
	"gql3/db"
	"time"
)

type User struct {
	ID              int64 `gorm:"primarykey" json:"id"`
	CreatedAt       time.Time
	UpdatedAt       time.Time
	Name            string `json:"name"`
	UserExtraInfoId int64
}

func (u *User) NewLoader() *UserLoader {
	return &UserLoader{
		wait:     2 * time.Millisecond,
		maxBatch: 100,
		fetch: func(keys []int64) ([]*User, []error) {
			users := make([]*User, len(keys))
			db.DB.Model(&User{}).Where("id in ?", keys).Find(&users)
			return users, nil

		},
	}
}
